package com.jlnk.stockdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.jlnk.stockdemo.R;
import com.jlnk.stockdemo.bean.BondsListResponse;

import java.util.List;

public class BondsAdapter extends RecyclerView.Adapter<BondsAdapter.BondsViewHolder> {
    private List<BondsListResponse.Data.Bonds> bondsItems;

    public BondsAdapter(List<BondsListResponse.Data.Bonds> bondsItems) {
        this.bondsItems = bondsItems;
    }

    @Override
    public BondsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_bonds_list, parent, false);
        return new BondsViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(BondsViewHolder holder, int position) {
        BondsListResponse.Data.Bonds bondsItem = bondsItems.get(position);
        holder.tv_bond_short_name.setText((String) bondsItem.getBond_short_name());
        holder.tv_stk_short_name.setText((String) bondsItem.getStk_short_name());
        holder.tv_remain_size.setText((String) bondsItem.getRemain_size());
        holder.tv_coupon_rate.setText((String) bondsItem.getCoupon_rate());
        holder.tv_add_rate.setText((String) bondsItem.getAdd_rate());

    }

    @Override
    public int getItemCount() {
        return bondsItems.size();
    }

    public static class BondsViewHolder extends RecyclerView.ViewHolder {
        TextView tv_bond_short_name;
        TextView tv_stk_short_name;
        TextView tv_remain_size;
        TextView tv_coupon_rate;
        TextView tv_add_rate;

        public BondsViewHolder(View itemView) {
            super(itemView);
            tv_bond_short_name = itemView.findViewById(R.id.tv_bond_short_name);
            tv_stk_short_name = itemView.findViewById(R.id.tv_stk_short_name);
            tv_remain_size = itemView.findViewById(R.id.tv_remain_size);
            tv_coupon_rate = itemView.findViewById(R.id.tv_coupon_rate);
            tv_add_rate = itemView.findViewById(R.id.tv_add_rate);
        }
    }
}
